//# sourceURL=http://uMapApp/Module/RoadModule
define([
    "mhjs/mhjs"
    , "uMap/uMap"
    , "uEarth/uEarth"
    , "./Module"
    , "../UI/Panel/FloatPanel"
    , "../UI/Panel/PanelBlock/TreeBlock"
    , "../UI/Panel/PanelBlock/ListBlock"
    , "../UI/Panel/PanelBlock/PropertiesBlock"
    , "../UI/Panel/Item/ListItem"
    , "../UI/Layer"
    , "../UI/Tree/Tree"
    , "./ETC/ETCModule"
    , "./StakeNum/StakeNumModule"
    , "./RoadLine/RoadLineModule"
    , "./RoadLine/RoadCenterStakeNumModule"
    , "./RoadLine/RoadSideStakeNumModule"
    , "./PQI/PQIModule"
    , "./Bridge/BridgeModule"
    , "./Bench/BenchModule"
    , "./Camera/CameraModule"
    , "./Camera/CameraBridgeModule"
    , "./Entrance/EntranceModule"
    , "./Loadometer/LoadometerModule"
    , "./RoadMaterials/RoadMaterialsModule"
    , "./Sign/SignModule"
    , "./SoundBench/SoundBenchModule"
    , "./WeatherGeter/WeatherGeterModule"
    , "./SoftRoad/SoftRoadModule"
    , "./Maintain/MaintainModule"
    , "./StakeNumDataModule"
    , "./Bridge/BridgeSinglePillarModule"
    , "./UavFlight/UavFlightsModule"
], function (
    mhjs
    , uMap
    , uEarth
    , Module
    , FloatPanel
    , TreeBlock
    , ListBlock
    , PropertiesBlock
    , ListItem
    , Layer
    , Tree
    , ETCModule
    , StakeNumModule
    , RoadLineModule
    , RoadCenterStakeNumModule
    , RoadSideStakeNumModule
    , PQIModule
    , BridgeModule
    , BenchModule
    , CameraModule
    , CameraBridgeModule
    , EntranceModule
    , LoadometerModule
    , RoadMaterialsModule
    , SignModule
    , SoundBenchModule
    , WeatherGeterModule
    , SoftRoadModule
    , MaintainModule
    , StakeNumDataModule
    , BridgeSinglePillarModule
    , UavFlightsModule
) {

    function RoadModule(option) {

        var _this = this;

        Module.call(_this, option);

        _this.title = "道路资产";
        _this.icon = _this.app.icons.layer;
        _this.panels = [];

        _this.leftPanel = new FloatPanel({"class": "leftPanel", "showMinMax": true, "title": "道路资产"});
        _this.leftPanel.treeBlock = new TreeBlock({"class": "fullBlock"});
        _this.leftPanel.append(_this.leftPanel.treeBlock);
        _this.leftPanel.treeBlock.title = _this.title;

        _this.panels.push(_this.leftPanel);

        _this.modules = [];

        _this.leftPanel.treeBlock.tree.GISTree = _this.leftPanel.treeBlock.tree.add(_this.loadGISTree());
        _this.leftPanel.treeBlock.tree.RoadTree = _this.leftPanel.treeBlock.tree.add(_this.loadRoadTree());

        //etc
        _this.etcModule = _this.loadRoadModule(new ETCModule({
            "request": _this.app.servers.DC.requests.etc,
            "map"    : _this.app.servers.DC.requests.ETC_map,
            "app"    : _this.app
        }));

        //zhs
        _this.stakeNumModule = _this.loadRoadModule(new StakeNumModule({
            "request": _this.app.servers.DC.requests.stakeNum,
            "map"    : _this.app.servers.DC.requests.stakeNum_map,
            "app"    : _this.app
        }));

        //道路边线
        _this.roadLineModule = _this.loadRoadModule(new RoadLineModule({
            "request"       : _this.app.servers.DC.requests.roadLine,
            "map"           : _this.app.servers.DC.requests.roadLine_map,
            "stakeNumModule": _this.stakeNumModule,
            "app"           : _this.app
        }));

        //百米桩(中心)
        _this.roadCenterStakeNumModule = _this.loadRoadModule(new RoadCenterStakeNumModule({
            "app"           : _this.app,
            "roadLineModule": _this.roadLineModule
        }));

        //百米桩(边界)
        _this.roadCenterStakeNumModule = _this.loadRoadModule(new RoadSideStakeNumModule({
            "app"    : _this.app,
            "request": _this.app.servers.DC.requests.stakeNum_side
        }));

        //PQI
        _this.PQIModule = _this.loadRoadModule(new PQIModule({
            "request"       : _this.app.servers.DC.requests.road_pqi,
            "map"           : _this.app.servers.DC.requests.road_pqi_map,
            "roadLineModule": _this.roadLineModule,
            "app"           : _this.app
        }));

        //道路养护
        _this.maintainModule = _this.loadRoadModule(new MaintainModule({
            "request"          : _this.app.servers.DC.requests.road_maintenance,
            "map"              : _this.app.servers.DC.requests.road_maintenance_map,
            "damageTypeRequest": _this.app.servers.DC.requests.damage_type,
            "app"              : _this.app
        }));

        //桥梁
        _this.bridgeModule = _this.loadRoadModule(new BridgeModule({
            "request": _this.app.servers.DC.requests.bridge,
            "map"    : _this.app.servers.DC.requests.bridge_map,
            "app"    : _this.app
        }));

        //护栏
        _this.benchModule = _this.loadRoadModule(new BenchModule({
            "request": _this.app.servers.DC.requests.bench,
            "map"    : _this.app.servers.DC.requests.bench_map,
            "app"    : _this.app
        }));

        //道路监控视频
        _this.cameraModule = _this.loadRoadModule(new CameraModule({
            "request": _this.app.servers.DC.requests.camera,
            "map"    : _this.app.servers.DC.requests.camera_map,
            "app"    : _this.app
        }));

        //桥梁监控视频
        _this.cameraBridgeModule = _this.loadRoadModule(new CameraBridgeModule({
            "request": _this.app.servers.DC.requests.camera_bridge,
            "map"    : _this.app.servers.DC.requests.camera_bridge_map,
            "positionRequest": _this.app.servers.DC.requests.camera_bridge_position,
            "app"    : _this.app
        }));

        //出入口
        _this.entranceModule = _this.loadRoadModule(new EntranceModule({
            "request": _this.app.servers.DC.requests.entrance,
            "map"    : _this.app.servers.DC.requests.entrance_map,
            "app"    : _this.app
        }));

        //称重设备
        _this.loadometerModule = _this.loadRoadModule(new LoadometerModule({
            "request": _this.app.servers.DC.requests.loadometer,
            "map"    : _this.app.servers.DC.requests.loadometer_map,
            "app"    : _this.app
        }));

        //路面材料
        _this.roadMaterialsModule = _this.loadRoadModule(new RoadMaterialsModule({
            "request"       : _this.app.servers.DC.requests.roadMaterials,
            "map"           : _this.app.servers.DC.requests.roadMaterials_map,
            "roadLineModule": _this.roadLineModule,
            "app"           : _this.app
        }));

        //标志标牌
        _this.signModule = _this.loadRoadModule(new SignModule({
            "request": _this.app.servers.DC.requests.sign,
            "map"    : _this.app.servers.DC.requests.sign_map,
            "app"    : _this.app
        }));

        //声屏障
        _this.soundBenchModule = _this.loadRoadModule(new SoundBenchModule({
            "request": _this.app.servers.DC.requests.soundBench,
            "map"    : _this.app.servers.DC.requests.soundBench_map,
            "app"    : _this.app
        }));

        //气象设备
        _this.weatherGeterModule = _this.loadRoadModule(new WeatherGeterModule({
            "request"           : _this.app.servers.DC.requests.weatherGeter,
            "map"               : _this.app.servers.DC.requests.weatherGeter_map,
            "app"               : _this.app,
            "weatherRequest"    : _this.app.servers.weather.requests.weather,
            "weatherRequestData": {"city": "吴江"}
        }));

        _this.app.ui.layout.left.append(_this.leftPanel);

        //软基路段
        _this.softRoadModule = _this.loadRoadModule(new SoftRoadModule({
            "request"      : _this.app.servers.DC.requests.softRoad,
            "extendRequest": _this.app.servers.DC.requests.softRoad_extend,
            "map"          : _this.app.servers.DC.requests.softRoad_map,
            "app"          : _this.app
        }));

        //单柱桥梁
        _this.bridgeSinglePillarModule = _this.loadRoadModule(new BridgeSinglePillarModule({
            "request"     : _this.app.servers.DC.requests.bridgeSinglePillar,
            "app"         : _this.app,
            "bridgeModule": _this.bridgeModule
        }));


        _this.stakeNumDataModules = {};

        //静态数据-服务区
        _this.stakeNumDataModules.serverAreaModule = _this.loadRoadModule(new StakeNumDataModule({
            "title"         : "服务区",
            "icon"          : _this.app.icons["服务区"],
            "request"       : _this.app.servers.DC.requests.stakeNumData_serverArea,
            "roadLineModule": _this.roadLineModule,
            "app"           : _this.app
        }));

        _this.stakeNumDataModules.bridgeModule = _this.loadRoadModule(new StakeNumDataModule({
            "title"         : "桥梁",
            "icon"          : _this.app.icons.bridge,
            "request"       : _this.app.servers.DC.requests.stakeNumData_bridge,
            "roadLineModule": _this.roadLineModule,
            "app"           : _this.app
        }));

        _this.stakeNumDataModules.longbridgeModule = _this.loadRoadModule(new StakeNumDataModule({
            "title"         : "长大桥",
            "icon"          : _this.app.icons["长大桥"],
            "request"       : _this.app.servers.DC.requests.stakeNumData_longbridge,
            "roadLineModule": _this.roadLineModule,
            "app"           : _this.app
        }));

        _this.stakeNumDataModules.tollgateModule = _this.loadRoadModule(new StakeNumDataModule({
            "title"         : "收费站",
            "icon"          : _this.app.icons["收费站"],
            "request"       : _this.app.servers.DC.requests.stakeNumData_tollgate,
            "roadLineModule": _this.roadLineModule,
            "app"           : _this.app
        }));

        _this.stakeNumDataModules.pivotModule = _this.loadRoadModule(new StakeNumDataModule({
            "title"         : "枢纽",
            "icon"          : _this.app.icons["枢纽"],
            "request"       : _this.app.servers.DC.requests.stakeNumData_pivot,
            "roadLineModule": _this.roadLineModule,
            "app"           : _this.app
        }));

        _this.stakeNumDataModules.interchangeModule = _this.loadRoadModule(new StakeNumDataModule({
            "title"         : "互通",
            "icon"          : _this.app.icons["互通"],
            "request"       : _this.app.servers.DC.requests.stakeNumData_interchange,
            "roadLineModule": _this.roadLineModule,
            "app"           : _this.app
        }));

        _this.app.ui.layout.left.append(_this.leftPanel);
    }

    var _class = RoadModule;

    mhjs.Inherit(_class, Module);

    Object.defineProperties(_class.prototype, {
        "loadGISTree"   : {
            value: function () {
                var _this = this;
                var tree = new Tree({
                    "title": _this.app.servers.GIS.title,
                    "list" : []
                });

                $.each(_this.app.servers.GIS.requests, function (i, request) {

                    var requestTree = new Tree({
                        "title": request.title,
                        "list" : []
                    });

                    $.each(_this.app.layers.GIS[request.name], function (i, layer) {

                        if (!layer.debug || _this.app.debug.isDebug) {

                            var layerTree = new Tree({
                                "title": layer.dataSource.title,
                                "layer": layer
                            });

                            requestTree.add(layerTree);

                        }


                    });

                    tree.add(requestTree);
                });


                return tree;
            }
        },
        "loadRoadModule": {
            value: function (module) {
                var _this = this;

                _this.modules.push(module);

                module.on("closePanel", function () {
                    _this.leftPanel.open(false);
                });
                _this.leftPanel.treeBlock.tree.RoadTree.add(new Tree({
                    "title": module.title || module.request.title,
                    "layer": $.extend(
                        module,
                        {
                            "active": function () {
                                if (module.isOpened) {
                                    if (!module.isPanelOpened) {
                                        module.openPanel();
                                    } else {
                                        module.close();
                                    }
                                } else {
                                    module.openPanel();
                                }
                            }
                        }
                    ),
                    "icon" : module.icon && module.icon.base64 || _this.app.icons.layer.base64
                }));

                return module;

            }
        },
        "loadRoadTree"  : {
            value: function () {
                var _this = this;
                var tree = new Tree({
                    "title": _this.app.servers.ROAD.title,
                    "list" : []
                });

                return tree;
            }
        },
        "open"          : {
            value: function () {
                var _this = this;
                _this.leftPanel.open(false);
                _this.leftPanel.max(false);
                _this.isOpened = true;
            }
        },
        "close"         : {
            value: function () {
                var _this = this;
                _this.closeAllPanel();
                _this.isOpened = false;
            }
        },
        "toggle"        : {
            value: function () {
                var _this = this;
                if (_this.isOpened) {
                    _this.close();
                } else {
                    _this.open();
                }
            }
        }
    });

    return _class;

});